#include "GLDirectKeyboardInput.h"


namespace mpgl_engine{ namespace application { namespace input {

	GLDirectKeyboardInput::GLDirectKeyboardInput()
	{
		m_inputBuffer = new char[MPGL_INPUT_BUFFER_SIZE];
		m_index = 0;
	}

	char GLDirectKeyboardInput::read()
	{
		//grab char
		char returnable = m_inputBuffer[0];

		//Shift the buffer to the left
		for(unsigned int i = 0; i < m_index; i++)
		{
			m_inputBuffer[i] = m_inputBuffer[i+1];
		}
		m_inputBuffer[m_index] = MPCON_BLANK_CHAR;
		m_index--;

		//Return the saved, first, char
		return returnable;
	}

	void GLDirectKeyboardInput::flush()
	{
		for(int i = 0; i <= m_index; i++)
		{
			m_inputBuffer[i] = MPCON_BLANK_CHAR;
		}
		m_index = 0;
	}

	bool GLDirectKeyboardInput::push(char chr)
	{
		if ( m_index >= MPGL_INPUT_BUFFER_SIZE )
			return false;
		m_inputBuffer[m_index] = chr;
		m_index++;
		return true;
	}

}}}